/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package group2assignone.view.manager;

import group2assignone.model.SaleReport;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Brad
 */
public class SalesReportTableView extends AbstractTableModel {

    private String[] columnNames = {"Flight Date", "Flight Number", "Ticket Price", "GST sum", "Airport Tax sum", "Availabe", "Sold", "%Utilization"};
    private String[][] data = null;
    private DateFormat formatter = new SimpleDateFormat("dd-MMM-yy");

    public SalesReportTableView(ArrayList<SaleReport> repList) {
        int row = 0;
        System.out.println("about to make table");
        if (!(repList == null)) {
            System.out.println("repList = " + repList.size());
            data = new String[repList.size()][columnNames.length];

            for (SaleReport rep : repList) {

                String bookingDate = formatter.format(rep.getBookDate());
                String flightNum = rep.getFlightNum();
                String ticketPrice = Double.toString(rep.getTicketPrice());
                String gst = Double.toString(rep.getGstCollect());
                String airTax = Double.toString(rep.getAirportTaxCollected());
                String seatsSold = Integer.toString(rep.getSeatsAvailable());
                String seatsTaken = Integer.toString(rep.getSeatsSold());
                String utilization = Double.toString(rep.getUtilization());
                int column = 0;
                data[row][column] = bookingDate;
                column++;
                data[row][column] = flightNum;
                column++;
                data[row][column] = ticketPrice;
                column++;
                data[row][column] = gst;
                column++;
                data[row][column] = airTax;
                column++;
                data[row][column] = seatsSold;
                column++;
                data[row][column] = seatsTaken;
                column++;
                data[row][column] = utilization;
                row++;

            }


        }
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        if (data != null) {
            return data.length;
        } else {
            return 0;
        }
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public String getValueAt(int row, int col) {
        return data[row][col];
    }

    /*
     * JTable uses this method to determine the default renderer/
     * editor for each cell.  If we didn't implement this method,
     * then the last column would contain text ("true"/"false"),
     * rather than a check box.
     */
    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        return false;
    }

    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    public void setValueAt(String value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }
}
